ARRAY_LENGTH block

Short summary

Name

ARRAY_LENGTH, ARRAY_LENGTH_2D, ARRAY_LENGTH_3DARRAY_LENGTH_4D

→POU type

→function

Category

IEC-blockMemoryEnh

Conform to →IEC-standard

(plus) not defined in IEC-standard

Graphical interface

Available since

Version 3.2.5 (for library Standard) – initial variant

Functionality

The block returns the size (the number of the elements) of the connected →array variable.

No check of invalid dimensions

When these blocks are used, Neuron Power Engineer does not check whether the connected array variable is of the correct dimension. For instance, when you connect a two-dimensional array variable with the input of ARRAY_LENGTH (here a one-dimensional array is required), it will not be possible to successfully build the application and load it onto the PLC.
Therefore, use other means (e.g. specify a unique name of the variable) so that you can easily detect that the connected array variable and the user block are matching regarding the dimension.

Inputs, outputs, return value

ARRAY_LENGTH

Identifier

→Data type

Description

In-outs
(VAR_IN_OUT):

IN

ARRAY [*] OF REALLREALUSINTUINTUDINTULINTSINTINTDINTLINTTIMEBOOLBYTEWORDDWORDLWORDSTRINGCHARDATE_AND_TIMEDATETIME_OF_DAY or a →user-defined data type

a one-dimensional array of variable length

Return value:

UDINT

number of the elements of the array

 

ARRAY_LENGTH_2D

Identifier

→Data type

Description

In-outs
(VAR_IN_OUT):

IN

ARRAY [*,*] OF  REALLREALUSINTUINTUDINTULINTSINTINTDINTLINTTIMEBOOLBYTEWORDDWORDLWORDSTRINGCHARDATE_AND_TIMEDATETIME_OF_DAY or a →user-defined data type

a two-dimensional array of variable length

Outputs:

DIM1

UDINT

number of the elements in dimension 1

DIM2

UDINT

number of the elements in dimension 2

Return value:

UDINT

number of all elements of the array

 

ARRAY_LENGTH_3D

Identifier

→Data type

Description

In-outs
(VAR_IN_OUT):

IN

ARRAY [*,*,*] OF  REALLREALUSINTUINTUDINTULINTSINTINTDINTLINTTIMEBOOLBYTEWORDDWORDLWORDSTRINGCHARDATE_AND_TIMEDATETIME_OF_DAY or a →user-defined data type

a three-dimensional array of variable length

Outputs:

DIM1

UDINT

number of the elements in dimension 1

DIM2

UDINT

number of the elements in dimension 2

DIM3

UDINT

number of the elements in dimension 3

Return value:

UDINT

number of all elements of the array

 

ARRAY_LENGTH_4D

Identifier

→Data type

Description

In-outs
(VAR_IN_OUT):

IN

ARRAY [*,*,*,*] OF  REALLREALUSINTUINTUDINTULINTSINTINTDINTLINTTIMEBOOLBYTEWORDDWORDLWORDSTRINGCHARDATE_AND_TIMEDATETIME_OF_DAY or a →user-defined data type

a four-dimensional array of variable length

Outputs:

DIM1

UDINT

number of the elements in dimension 1

DIM2

UDINT

number of the elements in dimension 2

DIM3

UDINT

number of the elements in dimension 3

DIM4

UDINT

number of the elements in dimension 4

Return value:

UDINT

number of all elements of the array

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Example for usage within ST-editor

The calculated values are evaluated by using the Assert block.

FUNCTION_BLOCK ExampleArrayLength
  VAR
    arrayVar1D : ARRAY [1..5] OF INT;
    arrayVar2D : ARRAY [2..5, 3..5] OF INT;
    arrayVar3D : ARRAY [1..6, 1..7, 1..8] OF INT;
    Dim1Var2, Dim2Var2, Dim1Var3, Dim2Var3, Dim3Var3 : UDINT;
    result1D, result2D, result3D : UDINT;
    eno1, eno2, eno3 : BOOL;
  END_VAR
  
  result1D := ARRAY_LENGTH(in:=arrayVar1D, ENO=>eno1);
  ASSERT(result1D=5);
  ASSERT(eno1);
  
  result2D := ARRAY_LENGTH_2D(in:=arrayVar2D, DIM1=>Dim1Var2, DIM2=>Dim2Var2, ENO=>eno2);
  ASSERT(result2D=12);
  ASSERT(Dim1Var2 = 4);
  ASSERT(Dim2Var2 = 3);
  ASSERT(eno2);
  
  result3D := ARRAY_LENGTH_3D(in:=arrayVar3D, DIM1=>Dim1Var3, DIM2=>Dim2Var3, DIM3=>Dim3Var3, ENO=>eno3);
  ASSERT(result3D=336);
  ASSERT(Dim1Var3 = 6);
  ASSERT(Dim2Var3 = 7);
  ASSERT(Dim3Var3 = 8);
  ASSERT(eno3);
 
  (* The usage of the ARRAY_LENGTH_4D block is similar to the other blocks. *)
  
END_FUNCTION_BLOCK

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.